﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;

using XMK.Framework.DataAccess;
using XMK.Tadong.Model;
using XMK.Utils;
using XMK.Framework.Model;
using XMK.Tadong.Model.Cond;


namespace XMK.Tadong.Data
{
    public class Base_DictData
    {
        /// <summary>
        /// 数据库连接
        /// </summary>
        protected DbProvider dbProvider;

        public Base_DictData(DbProvider dbProvider)
        {
            this.dbProvider = dbProvider;
        }



        public bool EditDictType(Base_DictTypeCond cond)
        {
            StringBuilder strSql = new StringBuilder();
            //action:0(删除)
            if (cond.action == 0)
            {
                List<DbCmdInfo> cmdlist = new List<DbCmdInfo>();
                strSql.Append("delete BASE_DICTTYPE WHERE DICTTYPE_ID=:p_DICTTYPE_ID");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "DICTTYPE_ID").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.OldDICTTYPE_ID);
                cmdlist.Add(cmd.DbCmdInfo);

                DbCmdHelper cmd2 = new DbCmdHelper(dbProvider, "delete BASE_DICTITEMS where DICTTYPE_ID=:p_DICTTYPE_ID",
                   delegate()
                   {
                       return DbCmdHelper.CreateParameters(dbProvider, "DICTTYPE_ID").ToArray();
                   });
                cmd2.DbCmdInfo.CommandType = CommandType.Text;
                cmd2.SetParamValues(cond.OldDICTTYPE_ID);
                cmdlist.Add(cmd2.DbCmdInfo);
                return DbManager.ExecTrans(dbProvider, cmdlist.ToArray());
            }
            else if (cond.action == 1)
            {

                List<DbCmdInfo> cmdlist = new List<DbCmdInfo>();
                strSql.Append("update BASE_DICTTYPE set DICTTYPE_ID=:p_DICTTYPE_ID,DICTTYPE_NAME=:p_DICTTYPE_NAME WHERE DICTTYPE_ID=:p_OLDDICTTYPE_ID ");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "DICTTYPE_ID", "DICTTYPE_NAME", "OLDDICTTYPE_ID").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.DICTTYPE_ID, cond.DICTTYPE_NAME, cond.OldDICTTYPE_ID);
                cmdlist.Add(cmd.DbCmdInfo);

                DbCmdHelper cmd2 = new DbCmdHelper(dbProvider, "update  BASE_DICTITEMS set DICTTYPE_ID=:p_DICTTYPE_ID where DICTTYPE_ID=:p_OLDDICTTYPE_ID",
                   delegate()
                   {
                       return DbCmdHelper.CreateParameters(dbProvider, "DICTTYPE_ID", "OLDDICTTYPE_ID").ToArray();
                   });
                cmd2.DbCmdInfo.CommandType = CommandType.Text;
                cmd2.SetParamValues(cond.OldDICTTYPE_ID, cond.OldDICTTYPE_ID);
                cmdlist.Add(cmd2.DbCmdInfo);
                return DbManager.ExecTrans(dbProvider, cmdlist.ToArray());
            }
            else if (cond.action == 2)
            {
                strSql.Append("INSERT INTO BASE_DICTTYPE ( DICTTYPE_ID,DICTTYPE_NAME");
                strSql.Append(") VALUES (:p_DICTTYPE_ID ,:p_DICTTYPE_NAME)");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "DICTTYPE_ID", "DICTTYPE_NAME").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.DICTTYPE_ID, cond.DICTTYPE_NAME);
                return DbManager.ExecNonQuery(cmd) > 0;
            }

            return false;
        }

        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool IsExistDictType(Base_DictTypeCond cond)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from  BASE_DICTTYPE WHERE DICTTYPE_ID=:p_DICTTYPE_ID and  DICTTYPE_ID!=:p_OLDDICTTYPE_ID");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                   delegate()
                   {
                       return DbCmdHelper.CreateParameters(dbProvider, "DICTTYPE_ID", "OLDDICTTYPE_ID").ToArray();
                   });
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(cond.DICTTYPE_ID, cond.OldDICTTYPE_ID);
            return DbManager.ExecNonQuery(cmd) > 0;
        }

        /// <summary>
        /// 类型列表
        /// </summary>
        /// <returns></returns>
        public List<Base_DictTypeInfo> QueryDictType(PageInfo pageInfo, OrderInfo order)
        {
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "sp_getpagedictlist",
                   delegate()
                   {
                       return DbCmdHelper.CreateParameters(dbProvider, true).ToArray();
                   });
            cmd.SetParamValues(order, pageInfo);
            List<Base_DictTypeInfo> dictList = DbManager.GetPageInfos<Base_DictTypeInfo>(cmd, pageInfo,
                delegate(out Base_DictTypeInfo dict, DataRow row)
                {
                    dict = new Base_DictTypeInfo
                    {
                        DICTTYPE_ID = ParseHelper.Parse<int>(row["DICTTYPE_ID"]),
                        DICTTYPE_NAME = ParseHelper.Parse<string>(row["DICTTYPE_NAME"])
                    };
                });
            return dictList;
        }



        /// <summary>
        ///  编辑字典元素
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool EditDictItem(Base_DictItemCond cond)
        {
            StringBuilder strSql = new StringBuilder();
            //action:0(删除)
            if (cond.action == 0)
            {

                strSql.Append("delete BASE_DICTITEMS WHERE DICTITEM_ID=:p_DICTITEM_ID");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "DICTITEM_ID").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.DICTITEM_ID);
                return DbManager.ExecNonQuery(cmd) > 0;

            }
            else if (cond.action == 1)
            {
                strSql.Append("update BASE_DICTITEMS set DICTTYPE_ID=:p_DICTTYPE_ID,ITEMNAME=:p_ITEMNAME,ITEMVALUE=:p_ITEMVALUE,ITEMORDER=:p_ITEMORDER,ITEMDESC=:p_ITEMDESC WHERE DICTITEM_ID=:p_DICTITEM_ID ");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "DICTTYPE_ID", "ITEMNAME", "ITEMVALUE", "ITEMORDER", "ITEMDESC", "DICTITEM_ID").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.DICTTYPE_ID, cond.ITEMNAME, cond.ITEMVALUE, cond.ITEMORDER, cond.ITEMDESC, cond.DICTITEM_ID);
                return DbManager.ExecNonQuery(cmd) > 0;
            }
            else if (cond.action == 2)
            {
                strSql.Append("INSERT INTO BASE_DICTITEMS ( DICTTYPE_ID,ITEMNAME,ITEMVALUE,ITEMORDER,ITEMDESC");
                strSql.Append(") VALUES (:p_DICTTYPE_ID,:p_ITEMNAME,:p_ITEMVALUE,:p_ITEMORDER,:p_ITEMDESC)");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "DICTTYPE_ID", "ITEMNAME", "ITEMVALUE", "ITEMORDER", "ITEMDESC").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.DICTTYPE_ID, cond.ITEMNAME, cond.ITEMVALUE, cond.ITEMORDER, cond.ITEMDESC);
                return DbManager.ExecNonQuery(cmd) > 0;
            }

            return false;
        }

        public Base_DictTypeInfo GetDictType(int dicttypeid)
        {
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "select DICTTYPE_ID,DICTTYPE_NAME from BASE_DICTTYPE where DICTTYPE_ID=:p_DICTTYPE_ID",
                   delegate()
                   {
                       return DbCmdHelper.CreateParameters(dbProvider, "DICTTYPE_ID").ToArray();
                   });
            cmd.SetParamValues(dicttypeid);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            Base_DictTypeInfo dictinfo = DbManager.GetInfo<Base_DictTypeInfo>(cmd,
                delegate(out Base_DictTypeInfo dict, DataRow row)
                {
                    dict = new Base_DictTypeInfo
                    {
                        DICTTYPE_ID = ParseHelper.Parse<int>(row["DICTTYPE_ID"]),
                        DICTTYPE_NAME = ParseHelper.Parse<string>(row["DICTTYPE_NAME"])
                    };
                });
            return dictinfo;
        }

        public List<Base_DictItemInfo> QueryDictItemList2(int DICTTYPE_ID)
        {
            return QueryDictItemList(DICTTYPE_ID, new PageInfo() { CurrentPage = 1, PageSize = int.MaxValue }, new OrderInfo());
        }

        public List<Base_DictItemInfo> QueryDictItemList(int DICTTYPE_ID, PageInfo pageInfo, OrderInfo order)
        {

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "sp_getpagedictitemlist",
                   delegate()
                   {
                       return DbCmdHelper.CreateParameters(dbProvider, true, "DICTTYPE_ID").ToArray();
                   });
            cmd.SetParamValues(order, pageInfo, DICTTYPE_ID);
            List<Base_DictItemInfo> dictList = DbManager.GetPageInfos<Base_DictItemInfo>(cmd, pageInfo,
                delegate(out Base_DictItemInfo dict, DataRow row)
                {
                    dict = new Base_DictItemInfo
                    {
                        DICTITEM_ID = ParseHelper.Parse<int>(row["DICTITEM_ID"]),
                        ITEMORDER = ParseHelper.Parse<int>(row["ITEMORDER"]),
                        ITEMDESC = ParseHelper.Parse<string>(row["ITEMDESC"]),
                        DICTTYPE_ID = ParseHelper.Parse<int>(row["DICTTYPE_ID"]),
                        ITEMNAME = ParseHelper.Parse<string>(row["ITEMNAME"]),
                        ITEMVALUE = ParseHelper.Parse<string>(row["ITEMVALUE"]),
                        DICTTYPE_NAME = ParseHelper.Parse<string>(row["DICTTYPE_NAME"])
                    };
                });
            return dictList;
        }




        public List<Dict_TableInfo> QueryDictTableList(PageInfo pageInfo, OrderInfo order)
        {
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "sp_getpagedicttablelist", () => { return DbCmdHelper.CreateParameters(dbProvider, true).ToArray(); });

            cmd.SetParamValues(order, pageInfo);
            List<Dict_TableInfo> dictList = DbManager.GetPageInfos<Dict_TableInfo>(cmd, pageInfo, (out Dict_TableInfo dictinfo, DataRow row) =>
            {
                dictinfo = new Dict_TableInfo()
                {
                    table_id = ParseHelper.Parse<int>(row["table_id"]),
                    desctription = ParseHelper.Parse<string>(row["desctription"]),
                    table_name = ParseHelper.Parse<string>(row["table_name"]),
                    table_code = ParseHelper.Parse<string>(row["table_code"]),
                    rqfield = ParseHelper.Parse<string>(row["rqfield"]),
                    iscurdb = ParseHelper.Parse<string>(row["iscurdb"]),
                    isinput = ParseHelper.Parse<string>(row["isinput"]),
                    isquery = ParseHelper.Parse<string>(row["isquery"]),
                    xh = ParseHelper.Parse<int>(row["xh"]),
                    authority = ParseHelper.Parse<int>(row["authority"]),
                    itemname = ParseHelper.Parse<string>(row["itemname"]),
                    itemdesc = ParseHelper.Parse<string>(row["ITEMDESC"]),
                    itemvalue = ParseHelper.Parse<int>(row["itemvalue"])
                };
            });

            return dictList;
        }

        public bool SaveTableAuthority(Base_TableAuthorityCond cond)
        {
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "update DICT_TABLE set authority=:p_authority where table_id=:p_table_id",
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "authority", "table_id").ToArray();
                    });
            cmd.SetParamValues(cond.authority, cond.tableid);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            return DbManager.ExecNonQuery(cmd) > 0;
        }

        public List<Dict_TableInfo> QueryDictTableRoleList(string roleId, PageInfo pageInfo, OrderInfo order)
        {
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "sp_getpagedicttablerolelist", () => { return DbCmdHelper.CreateParameters(dbProvider, true, "ROLEID").ToArray(); });

            cmd.SetParamValues(order, pageInfo, roleId);
            List<Dict_TableInfo> dictList = DbManager.GetPageInfos<Dict_TableInfo>(cmd, pageInfo, (out Dict_TableInfo dictinfo, DataRow row) =>
            {
                dictinfo = new Dict_TableInfo()
                {
                    table_id = ParseHelper.Parse<int>(row["table_id"]),
                    desctription = ParseHelper.Parse<string>(row["desctription"]),
                    table_name = ParseHelper.Parse<string>(row["table_name"]),
                    table_code = ParseHelper.Parse<string>(row["table_code"]),
                    rqfield = ParseHelper.Parse<string>(row["rqfield"]),
                    iscurdb = ParseHelper.Parse<string>(row["iscurdb"]),
                    isinput = ParseHelper.Parse<string>(row["isinput"]),
                    isquery = ParseHelper.Parse<string>(row["isquery"]),
                    xh = ParseHelper.Parse<int>(row["xh"]),
                    authority = ParseHelper.Parse<int>(row["authority"]),
                    //itemname = ParseHelper.Parse<string>(row["itemname"]),
                    itemvalue = ParseHelper.Parse<int>(row["roleright"])
                };
            });

            return dictList;
        }

        public bool QueryDictTableRoleSave(Base_StrcutRoleCond cond)
        {
            List<DbCmdInfo> cmdlist = new List<DbCmdInfo>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete BASE_STRUCTROLERIGHT WHERE ROLES_ID=:p_ROLES_ID and STRUCTTABLEID=:p_STRUCTTABLEID");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "ROLES_ID", "STRUCTTABLEID").ToArray();
                });
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(cond.ROLES_ID, cond.STRUCTTABLEID);
            cmdlist.Add(cmd.DbCmdInfo);

            StringBuilder strSql2 = new StringBuilder();
            strSql2.Append("INSERT INTO BASE_STRUCTROLERIGHT ( STRUCTROLEID,ROLES_ID,STRUCTTABLEID,AUTHORITY");
            strSql2.Append(") VALUES (:p_STRUCTROLEID,:p_ROLES_ID,:p_STRUCTTABLEID,:p_AUTHORITY)");
            DbCmdHelper cmd2 = new DbCmdHelper(dbProvider, strSql2.ToString(),
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "STRUCTROLEID", "ROLES_ID", "STRUCTTABLEID", "AUTHORITY").ToArray();
                });
            cmd2.DbCmdInfo.CommandType = CommandType.Text;
            cmd2.SetParamValues(Guid.NewGuid().ToString(), cond.ROLES_ID, cond.STRUCTTABLEID, cond.AUTHORITY);
            cmdlist.Add(cmd2.DbCmdInfo);
            return DbManager.ExecTrans(dbProvider, cmdlist.ToArray());

        }

        public bool GetUserStructTableRight(Base_StructTableRightCond cond)
        {
            try
            {
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, "select count(*) from base_structroleright a inner join base_userrole b on a.roles_id=b.roles_id and b.user_id=:p_user_id and a.structtableid=:p_tableid inner join dict_table c on c.table_id=:p_tableid and c.authority<=a.authority",
                        delegate()
                        {
                            return DbCmdHelper.CreateParameters(dbProvider, "user_id", "tableid").ToArray();
                        });
                cmd.SetParamValues(cond.UserId, cond.TableId);
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                int count = Convert.ToInt32(DbManager.ExecScalar(cmd));
                return count > 0;
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
            return false;
        }

        public bool GetUserFileRoleRight(Base_FileRoleOper cond)
        {
            string spaceName;
            if (cond.SpaceType == "10")
                spaceName = "tb_person_file";
            else if (cond.SpaceType == "20")
                spaceName = "tb_team_file";
            else
                spaceName = "tb_xmk_file";
            string cmdsql;
            if (cond.OpreType == "10")
                cmdsql = "select count(*) from base_userrole a inner join base_fileroleright b on a.roles_id=b.roles_id inner join " + spaceName + " c on c.file_id=:p_file_id and  a.user_id=:p_user_id and b.SEE_SECR>=c.secret_lvl";
            else if (cond.OpreType == "20")
                cmdsql = "select count(*) from base_userrole a inner join base_fileroleright b on a.roles_id=b.roles_id inner join " + spaceName + " c on c.file_id=:p_file_id and  a.user_id=:p_user_id and b.DOWN_PDF_SECR>=c.secret_lvl";
            else
                cmdsql = "select count(*) from base_userrole a inner join base_fileroleright b on a.roles_id=b.roles_id inner join " + spaceName + " c on c.file_id=:p_file_id and  a.user_id=:p_user_id and b.DOWN_SOURCE_SECR>=c.secret_lvl";
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, cmdsql,
            delegate()
            {
                return DbCmdHelper.CreateParameters(dbProvider, "user_id", "file_id").ToArray();
            });
            cmd.SetParamValues(cond.UserId, cond.FileId);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int count = Convert.ToInt32(DbManager.ExecScalar(cmd));
            return count > 0;

        }
        /// <summary>
        /// 是否有范围权限
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool GetUserAreaRoleRight(Base_FileRoleOper cond)
        {
            if (cond.SpaceType == "10")
            { //个人空间
                return true;
            }
            if (cond.SpaceType == "20")
            { //课题组文件
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, "SELECT count(*) from tb_team_file a inner join tb_team_user b on a.team_id=b.team_id and a.FILE_ID=:p_file_id and b.user_id=:p_user_id",
                  delegate()
                  {
                      return DbCmdHelper.CreateParameters(dbProvider, "user_id", "file_id").ToArray();
                  });
                cmd.SetParamValues(cond.UserId, cond.FileId);
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                int count = Convert.ToInt32(DbManager.ExecScalar(cmd));
                return count > 0;
            }
            else
            { //项目库文件
                string cmdsql = "SELECT count(*) from tb_team_user a inner join tb_team b on  a.team_id=b.team_id  and a.USER_ID=:p_user_id and b.team_name=" + "'项目库空间'";
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, cmdsql,
                  delegate()
                  {
                      return DbCmdHelper.CreateParameters(dbProvider, "user_id", "file_id").ToArray();
                  });
                cmd.SetParamValues(cond.UserId);
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                int count = Convert.ToInt32(DbManager.ExecScalar(cmd));
                return count > 0;
            }
            //return false;

        }

        public Dict_TableInfo GetCurTableInfoByTableCode(string table_code)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT * FROM DICT_TABLE WHERE TABLE_CODE ='" + table_code + "'");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            Dict_TableInfo Obj = DbManager.GetInfo(cmd,
                delegate(out Dict_TableInfo u, DataRow row)
                {
                    u = new Dict_TableInfo
                    {
                        table_id = ParseHelper.Parse<int>(row["table_id"]),
                        desctription = ParseHelper.Parse<string>(row["desctription"]),
                        table_name = ParseHelper.Parse<string>(row["table_name"]),
                        table_code = ParseHelper.Parse<string>(row["table_code"]),
                        rqfield = ParseHelper.Parse<string>(row["rqfield"]),
                        iscurdb = ParseHelper.Parse<string>(row["iscurdb"]),
                        isinput = ParseHelper.Parse<string>(row["isinput"]),
                        isquery = ParseHelper.Parse<string>(row["isquery"]),
                        xh = ParseHelper.Parse<int>(row["xh"]),
                        authority = ParseHelper.Parse<int>(row["authority"])


                    };
                });
            return Obj;
        }

        public Base_FileRoleRightCond GetCurrentFileOpre(string roles_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT * FROM BASE_FILEROLERIGHT WHERE ROLES_ID='" + roles_id + "'");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            Base_FileRoleRightCond Obj = DbManager.GetInfo(cmd,
                delegate(out Base_FileRoleRightCond u, DataRow row)
                {
                    u = new Base_FileRoleRightCond
                    {
                        FILEROLEID = ParseHelper.Parse<string>(row["FILEROLEID"]),
                        ROLES_ID = ParseHelper.Parse<string>(row["ROLES_ID"]),
                        SEE_SECR = ParseHelper.Parse<decimal>(row["SEE_SECR"]),
                        DOWN_PDF_SECR = ParseHelper.Parse<decimal>(row["DOWN_PDF_SECR"]),
                        DOWN_SOURCE_SECR = ParseHelper.Parse<decimal>(row["DOWN_SOURCE_SECR"])

                    };
                });
            return Obj;

        }
        /// <summary>
        /// 获取结构化业务表列表
        /// </summary>
        /// <param name="roles_id"></param>
        /// <returns></returns>
        public List<Base_StructTableProCond> QueryStructTableProList(PageInfo pageInfo, OrderInfo order)
        {

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "sp_getstructTableProlist",
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, true).ToArray();
                    });
            cmd.SetParamValues(order, pageInfo);
            List<Base_StructTableProCond> exttypeList = DbManager.GetPageInfos<Base_StructTableProCond>(cmd, pageInfo,
                delegate(out Base_StructTableProCond dict, DataRow row)
                {
                    dict = new Base_StructTableProCond
                    {
                        T_CODE = ParseHelper.Parse<int>(row["T_CODE"]),
                        T_ENG_NAME = ParseHelper.Parse<string>(row["T_ENG_NAME"]),
                        T_CN_NAME = ParseHelper.Parse<string>(row["T_CN_NAME"]),
                        T_PROC_NAME = ParseHelper.Parse<string>(row["T_PROC_NAME"]),
                        T_CAT = ParseHelper.Parse<string>(row["T_CAT"]),
                        EN_T_CAT = ParseHelper.Parse<string>(row["EN_T_CAT"]),
                        T_FIELD = ParseHelper.Parse<string>(row["T_FIELD"])

                    };
                });
            return exttypeList;
        }

        /// <summary>
        /// 获取结构业务表
        /// </summary>
        /// <param name="roles_id"></param>
        /// <returns></returns>
        public Base_StructTableProCond GetStructTablePro(int id)
        {

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "SELECT * FROM tb_table_dict where T_CODE=:p_T_CODE",
                   delegate()
                   {
                       return DbCmdHelper.CreateParameters(dbProvider, "T_CODE").ToArray();
                   });
            cmd.SetParamValues(id);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            Base_StructTableProCond dictinfo = DbManager.GetInfo<Base_StructTableProCond>(cmd,
                delegate(out Base_StructTableProCond dict, DataRow row)
                {
                    dict = new Base_StructTableProCond
                      
                    {
                        T_CODE = ParseHelper.Parse<int>(row["T_CODE"]),
                        T_ENG_NAME = ParseHelper.Parse<string>(row["T_ENG_NAME"]),
                        T_CN_NAME = ParseHelper.Parse<string>(row["T_CN_NAME"]),
                        T_PROC_NAME = ParseHelper.Parse<string>(row["T_PROC_NAME"]),
                        T_CAT = ParseHelper.Parse<string>(row["T_CAT"]),
                        EN_T_CAT = ParseHelper.Parse<string>(row["EN_T_CAT"]),
                        T_FIELD = ParseHelper.Parse<string>(row["T_FIELD"])
                    };
                });
            return dictinfo;
        }

        public bool EditStructTablePro(Base_StructTableProCond cond)
        {
            StringBuilder strSql = new StringBuilder();
           
            List<DbCmdInfo> cmdlist = new List<DbCmdInfo>();
            strSql.Append("update tb_table_dict set T_CAT=:p_T_CAT,T_FIELD=:p_T_FIELD WHERE T_CODE=:p_T_CODE ");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "T_CAT", "T_FIELD", "T_CODE").ToArray();
                });
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(cond.T_CAT, cond.T_FIELD, cond.T_CODE);
            cmdlist.Add(cmd.DbCmdInfo);
            return DbManager.ExecTrans(dbProvider, cmdlist.ToArray());

            return false;
        }
    }
}
